package Java8NewLearn.MethodsQuote;



import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 一、构造器引用
 *      和方法引用类似，函数式接口的抽象方法的形参列表和构造器的形参列表一致
 *      抽象方法的返回值类型即为构造器构造的对象的类型
 * 二、数组引用
 *      把数组看作一个特殊的类，写法同上
 *
 * Created by shkstart
 */
public class ConstructorRefTest {
	//构造器引用
    //Supplier中的T get()
    @Test
    public void test1(){
        Supplier<Employee> sup1=()->new Employee();
        System.out.println(sup1.get());
        System.out.println("******************");

        Supplier<Employee> sup2=Employee::new;
        System.out.println(sup2.get());
	}

	//Function中的R apply(T t)
    @Test
    public void test2(){
        Function<Integer,Employee> func1=id->new Employee(id);
        System.out.println(func1.apply(12));

        System.out.println("***************************");

        Function<Integer,Employee> func2=Employee::new;
        System.out.println(func2.apply(13));
	}

	//BiFunction中的R apply(T t,U u)
    @Test
    public void test3(){
        BiFunction<Integer,String,Employee> bifunc1=(id,name)->new Employee(id,name);
        System.out.println(bifunc1.apply(12,"tom"));

        System.out.println("*******************************");

        BiFunction<Integer,String,Employee> bifunc2=Employee::new;
        System.out.println(bifunc2.apply(13,"jerry"));
	}

	//数组引用
    //Function中的R apply(T t)
    @Test
    public void test4(){
        Function<Integer,String[]> func1=length->new String[length];
        System.out.println(func1.apply(6).length);

        System.out.println("******************************");

        Function<Integer,String[]> func2=String[]::new;
        System.out.println(func2.apply(12).length);
	}
}
